<?php
class Product_Service_Attached
{

    public static function getProductPicture($productId){
		$picture = Product_Model_Attached::getInstance()->getByProductId($productId)->toArray();
		if($picture){
			return $picture[0];
		}
		return false;
	}
	
	public  static function getPicturePath($customerId,$fileName,$productId=null){
		$path = APPLICATION_PATH."/../../front/data/images/$customerId/";
		if(!empty($productId)){
			$path="$productId/";
		}
		$path.="$fileName";
		if(empty($fileName)||empty($customerId)){
			$path = APPLICATION_PATH."/../public/images/noimg.jpg";	
		}	
		if(!file_exists($path)){
			$path = APPLICATION_PATH."/../public/images/noimg.jpg";
		}
		return  file_get_contents($path);
	}
	
    public static function deleteImgByProductId($productId){
		$rows = Product_Model_Attached::getInstance()->deleteImgByProductId($productId);
        return $rows;
	}
	
	public static function getByCondition($condition=array(),$type='*',$order=array('pa_sort'), $pageSize=0, $page=1)
	{ 
		$obj=new Product_Model_Attached();
		$rows= $obj->getByCondition( $condition,$type,$order, $pageSize,$page);	
		return $rows;
	}

	public static function getByfield($field,$value)
	{ 
		$obj=new Product_Model_Attached();
		$rows= $obj->getByfield($field,$value);
		if(!empty($rows)){
			$rows=$rows->toArray();
		}
		return $rows;
	}
	
	public static function getByProductId($t_id)
	{ 
		$obj=new Product_Model_Attached();
		$rows=$obj->getByProductId($t_id);
		if(!empty($rows)){
			$rows=$rows->toArray();
		}
		return $rows;
	}
	
	public static function create($row)
	{ 
		$obj=new Product_Model_Attached();
		return $obj->create($row);
	}

	public static function update($row,$t_id)
	{ 
		$obj=new Product_Model_Attached();
		return $obj->update($row,$t_id);
	}
	/**
	*根据Product_id删除所有附件
	*/
	public static function delete($id)
	{ 
		$obj=new Product_Model_Attached();
		return $obj->delete($id);
	}

}